package Josefu_link;

import java.util.Scanner;
class Node
{
	String _name;
	int _id;
	Node _next;
	
	public Node(String name,int id)
	{
		_name = name;
		_id = id;
		_next = null;
	}
}

class List
{
	Node head;
	Node tail;
	
	public List()
	{
		head = new Node("", 0);
		tail = new Node("", 0);
		head._next = tail;
		tail._next = head;
	}
	
	public void add(String name,int id)
	{
		System.out.println(name);
		System.out.println(id);
		Node newnode = new Node(name, id);
		Node next = tail._next;
		tail._next = newnode;
		tail = newnode;
		tail._next = next;
	}
	
	public void delete(Node node)
	{
		Node cur = head;
		while(cur._next != node)
		{
			cur = cur._next;
		}
		
		cur._next = node._next;
	}
	
	public void print_link()
	{
		Node cur = head._next._next;
		
		while(cur != head)
		{
			System.out.println(cur._name);
			System.out.println(cur._id);
			
			cur = cur._next;
		}
	}
}


public class Josefu_link {

	public static void main(String[] args) {
		List Josefu = new List();
		Scanner in = new Scanner(System.in);
		System.out.println("请输入人数");
		int num = in.nextInt();
		System.out.println(num);
		in.nextLine();
		
		System.out.println("请输入跳过的数字");
		int skip_num = in.nextInt();
		System.out.println(skip_num);
		in.nextLine();
		
		for(int i = 0;i < num;++i)
		{
			System.out.println("请输入第"+(i+1)+"个人的名字");
			String name = in.nextLine();
			int id = i + 1;
			Josefu.add(name, id);
		}
		
		in.close();
		//System.out.println(Josefu.head._name);
		Josefu.print_link();
		
		Josefu = Josefu_solve(Josefu,skip_num);
		
		System.out.println("hahah");
		Josefu.print_link();
	}
	
	public static List Josefu_solve(List Josefu,int skip_num)
	{
		Node cur = Josefu.head._next._next;
		int num = 0;
		while(Josefu.head._next._next._next != Josefu.head)
		{
			if(cur == Josefu.head || cur == Josefu.head._next)
			{
				cur = cur._next;
				continue;
			}
			++num;
			if(num == skip_num)
			{
				Node delete = cur;
				cur = cur._next;
				Josefu.delete(delete);
				num = 0;
			}
			else 
			{
				cur = cur._next;
			}
		}
		return Josefu;
	}
}
